package com.pwt.repository;

import com.pwt.repository.base.BaseRepository;
import com.pwt.entity.PowerModule;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * PowerModule Repository层
 *
 * @author auto generated
 * @date 2021-12-17 11:08:55
 */
public interface PowerModuleRepository extends BaseRepository<PowerModule, String> ,PowerModuleRepositoryExtension{

    @Query(nativeQuery = true,value = "select top 1 * from power_module order by end_time desc ")
    public PowerModule queryPowerModuleOrderBy();

    @Query(nativeQuery = true,value = "select  * from power_module where k0010=?1 and begin_time >= ?2 and end_time <=?3 ")
    public List<PowerModule> queryPowerModuleByK0010AndBeginTimeAndEndTime(Integer k0010,String beginTime, String endTime);

    @Query(nativeQuery = true,value = "select k1000 from power_module where k0010=?1 and begin_time >= ?2 and end_time <=?3  group by k1000")
    public List<Integer> queryPowerModuleGroupByK1000(Integer k0010,String beginTime, String endTime);

    @Transactional(rollbackFor = Exception.class)
    @Query(nativeQuery = true,value = "delete from power_module where begin_time >= ?1 and end_time <=?2")
    @Modifying(clearAutomatically = true)
    public void deleteByBeginTimeAndEndTime(Date beginTime,Date endTime);




}
